package cn.iocoder.yudao.module.product.sku.vo;

import cn.iocoder.yudao.module.api.product.sku.dto.ProductPropertyValueRespDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.util.List;

@Schema(description = "管理后台 - 产品 SKU 创建/更新 Request VO")
@Data
@Valid
public class ProductSkuSaveReqVO {

    @Schema(description = "产品 SKU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉小短袖")
    @NotEmpty(message = "产品 SKU 名字不能为空")
    private String name;

    @Schema(description = "销售价，单位：分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1999")
    @NotNull(message = "销售价不能为空")
    @Min(0)
    private int price;

    @Schema(description = "成本价，单位：分", example = "19")
    @PositiveOrZero
    private int costPrice;

    @SuppressWarnings("unused")
    @AssertTrue(message = "成本成本价不能大于销售价")
    public boolean validateCostPrice() {
        if (price == 0) {
            return true;
        }
        if (costPrice == 0) {
            return true;
        }
        return costPrice <= price;
    }

    @Schema(description = "市场价，单位：分", example = "2999")
    @PositiveOrZero
    private int marketPrice;

    @Schema(description = "会员价，单位：分", example = "1999")
    @PositiveOrZero
    private int vipPrice;

    @Schema(description = "厂家零售价，单位：分。如果填写了则支持零售，不填则只支持批发。", example = "2999")
    @PositiveOrZero
    private int wholesaleForRetailPrice;

    @Schema(description = "条形码", example = "202404051353520")
    private String barCode;

    @Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.example.com/xx.png")
    @NotNull(message = "图片地址不能为空")
    private String picUrl;

    @Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
    @NotNull(message = "库存不能为空")
    private int stock;

    @Schema(description = "产品重量,单位：kg 千克", example = "1.2")
    private double weight;

    @Schema(description = "产品体积,单位：m^3 平米", example = "2.5")
    private double volume;

    @Schema(description = "属性数组")
    private List<ProductPropertyValueRespDTO> properties;

    public List<ProductPropertyValueRespDTO> getProperties() {
        if (properties == null) {
            properties = List.of(ProductPropertyValueRespDTO.DEFAULT);
        }
        return properties;
    }

}
